<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TTS网页示例</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 50px;
        }
        #text-input {
            width: 300px;
            height: 100px;
            margin-bottom: 20px;
        }
        #play-button {
            padding: 10px 20px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <h1>文本转语音示例</h1>
    <textarea id="text-input" placeholder="请输入要转换的文本..."></textarea>
    <br>
    <button id="play-button">播放</button>

    <script>
        const textInput = document.getElementById('text-input');
        const playButton = document.getElementById('play-button');

        playButton.addEventListener('click', () => {
            const text = textInput.value;
            if (text) {
                const utterance = new SpeechSynthesisUtterance(text);
                utterance.lang = 'zh-CN'; // 设置语言为中文
                window.speechSynthesis.speak(utterance);
            } else {
                alert('请输入要转换的文本！');
            }
        });
    </script>
</body>
</html>